package chris.delayMessage;

import chris.ConFactory;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Server
 *
 * @author nanxin.chen
 * @since 2017/8/1
 */
public class DelayRecv {

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory cf = ConFactory.getConnectionFactory();
        Connection con = cf.newConnection();
        Channel channel = con.createChannel();

        Consumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                String msg = new String(body, "utf-8");
                System.out.println("received : " + msg);
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        };
        channel.basicConsume(DelaySend.queueName, false, consumer);


    }

}
